﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OracleClient;
public partial class changyong_wuliu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
      public void BindData()
    {
        string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";
        string sqlstr = "select * from booksale. deliver_goods order by 图书编号";
        OracleConnection con = new OracleConnection(connet);
        OracleDataAdapter da = new OracleDataAdapter(sqlstr, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Gv1.DataSource = ds;
        Gv1.DataKeyNames = new string[] { "图书编号" };
        Gv1.DataBind();


    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";
        string sqlstr = "select * from booksale.deliver_goods where 图书编号='" +bookid.Text + "' or 图书名称='" + bookname.Text + "'";
        OracleConnection con = new OracleConnection(connet);
        OracleDataAdapter da = new OracleDataAdapter(sqlstr, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Gv1.DataSource = ds;
        Gv1.DataKeyNames = new string[] { "图书编号" };
        Gv1.DataBind();
    }

    protected void Gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {


        string id = Gv1.DataKeys[e.RowIndex].Value.ToString();
        string bookname= ((TextBox)(Gv1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        string delivery = ((TextBox)(Gv1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
        string express = ((TextBox)(Gv1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
        //string date = ((TextBox)(Gv1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
        string update = "update booksale.Book_Pub set 图书名称='" + bookname + "',发货时间='" + delivery + "',快递='" + express + "' where 图书编号='" + id + "'";


        bool i = ConnectSQL(update);
        if (i)
        {
            Response.Write("<script language=javascript>alert('修改成功')</script");
            Gv1.EditIndex = -1;
            BindData();
        }
        else { Response.Write("<script language=javascript>alert('修改失败')</script"); }




    }



    public bool ConnectSQL(string strSqlCom)
    {
        string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";
        OracleConnection con = new OracleConnection(connet);
        OracleCommand com = new OracleCommand(strSqlCom, con);
        try
        {
            if (con.State == System.Data.ConnectionState.Closed)
            { con.Open(); }
            com.ExecuteNonQuery();
            return true;


        }
        catch
        { return false; }
        finally
        { con.Close(); }
    }
    protected void Gv1_RowEditing(object sender, GridViewEditEventArgs e)
    {

        Gv1.EditIndex = e.NewEditIndex;
        BindData();
    }
    protected void Gv1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        Gv1.EditIndex = -1;
        BindData();
    }

    protected void Gv1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Gv1.PageIndex = e.NewPageIndex;
        BindData();
    }
    protected void Gv1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string delete_sql = "delete from booksale. deliver_goods where 图书编号='" + Gv1.DataKeys[e.RowIndex].Value.ToString() + "'";
        bool delete = ConnectSQL(delete_sql);
        if (delete)
        {
            Response.Write("<script language=javascript>alert('删除成功！')</script>");
            BindData();
        }
        else
        {
            Response.Write("<script language=javascript>alert('删除失败！')</script>");
        }
    }
}